<?php
/*
 * SAE_MYSQL_USER:用户名 
 * SAE_MYSQL_PASS：密码： 
 * SAE_MYSQL_HOST_M：主库域名
 * SAE_MYSQL_HOST_S：从库域名 
 * SAE_MYSQL_PORT：端口： 
 * SAE_MYSQL_DB数据库名 app_localmobile
 * 
 * 详细说明：页面的编码要和数据库的编码一样，不然会出现乱码
 * 或者在连接数据库时设置mysql_set_charset()
 * 
 */

/**
 * 数据库配置
 */

$db_config = array(
    'dev' => array(
        'user' => 'root',
        'pass' => 'root',
        'host' => 'localhost',
        'port' => '3306',
        'dbname' => 'ddr_mobile',
    ),
    'sae' => array(
        'user' => SAE_MYSQL_USER,
        'pass' => SAE_MYSQL_PASS,
        'host' => SAE_MYSQL_HOST_M,
        'port' => SAE_MYSQL_PORT,
        'dbname' => SAE_MYSQL_DB,
    ), 
    'kvmla' => array(
        'user' => 'dangdiren',
        'pass' => 'ddrsql-123',
        'host' => 'localhost',
        'port' => '3306',
        'dbname' => 'dangdiren',
    ),
);


// 判断域名选用不同数据库配置
$domain = $_SERVER['SERVER_NAME'];

$env = 'kvmla';
if ($domain == 'localhost') {
    $env = 'dev';
}

// echo $env;

$link = mysql_connect($db_config[$env]['host'] . ':' . $db_config[$env]['port'], $db_config[$env]['user'], $db_config[$env]['pass'] );

if ($link) {
    mysql_select_db($db_config[$env]['dbname'], $link);
}
else {
    echo "数据库连接失败";
}

?>